#pragma once 

#include <string>
#include <ctemplate/template.h>

#include "oj_mysql_model.hpp"
// #include "oj_model.hpp"

namespace rs_view
{
    using namespace rs_model;
    class View
    {

        const std::string html_path = "./template_html/";
        public:
        View()
        {}
        ~View()
        {}
        public:
        void AllExpandHtml(const vector<struct rs_model::Question> &questions,std::string *html)
        {
            std::string src_html = html_path + "all_questions.html";

            ctemplate::TemplateDictionary root("all_questions");

            for(auto& q:questions)
            {
                ctemplate::TemplateDictionary *sub = root.AddSectionDictionary("question_list");
                sub->SetValue("number",q.number);
                sub->SetValue("title",q.title);
                sub->SetValue("grade",q.grade);
            }

            ctemplate::Template *tpl = ctemplate::Template::GetTemplate(src_html,ctemplate::DO_NOT_STRIP);

            tpl->Expand(html,&root);
        }

        void OneExpandHtml(const struct rs_model::Question &q,std::string*html)
        {
            std::string src_html = html_path + "one_question.html";

            ctemplate::TemplateDictionary root("one_question");

            root.SetValue("number",q.number);
            root.SetValue("title",q.title);
            root.SetValue("grade",q.grade);
            root.SetValue("desc",q.desc);
            root.SetValue("pre_code",q.header);

             ctemplate::Template *tpl = ctemplate::Template::GetTemplate(src_html,ctemplate::DO_NOT_STRIP);

             tpl->Expand(html,&root);
        }
        
    };
}